﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFormDoiMatKhau : DevExpress.XtraEditors.XtraForm
    {
        public XtraFormDoiMatKhau()
        {
            InitializeComponent();
        }

        private void txtTenDN_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtMKCU.Focus();
        }

        private void txtMKCU_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtMKMOI.Focus();
        }

        private void txtMKMOI_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                btnOK_Click(sender, e);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DataTableReader dtr = BAL_TAIKHOAN.LayTaiKhoan().CreateDataReader();
            while(dtr.Read())
            {
                if (dtr["TenDangNhap"].ToString().Equals(txtTenDN.Text) && dtr["MatKhau"].ToString().Equals(txtMKCU.Text))
                {
                    BAL_TAIKHOAN.DoiMatKhau(txtTenDN.Text, txtMKMOI.Text);
                    MessageBox.Show("Bạn đã thay đổi mật khẩu thành công!!!");
                    break;
                }
                else
                    MessageBox.Show("Tên đăng nhập hoặc tài khoản không đúng!!!");
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            txtTenDN.ResetText();
            txtMKCU.ResetText();
            txtMKMOI.ResetText();
        }
    }
}